package www.member.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.json.simple.JSONObject;

import www.Action;
import www.ActionForward;
import www.member.MemberDTO;
import www.member.MemberMgr;
import www.utility.Utility;

public class MemberCreate implements Action {
     @Override
    public ActionForward execute(HttpServletRequest request, HttpServletResponse response) throws Throwable {
         System.out.println("membercreate executed");
//         http://211.241.228.81:9095/Android1_2/member/create.do
//         ?id=tt&introduce=ttintro&nickname=ttnick&profilephoto=ttphoto&password=tt&email=tt&memlevel=tt
         String id = request.getParameter("id");
         String nickname = request.getParameter("nickname");
         
         nickname = Utility.byteToString(nickname);
         
         request.setCharacterEncoding("euc-kr");
         
         MemberMgr mgr = new MemberMgr();
         MemberDTO dto = new MemberDTO();
         
         dto.setId(id);
         dto.setNickname(nickname);
         
         JSONObject obj = new JSONObject(); 
         
         try{
             int retval = (Integer) mgr.create(dto);
             System.out.println("retval: "+retval);
         if(retval == 1){
                 obj.put("code","success");
                 obj.put("message", "success.");
         }else{
               obj.put("retval",retval);
               obj.put("code","error");
               obj.put("message", "error.");
           }
         }catch(Exception e){
             System.out.println(e);
         }finally{
             
         }
             System.out.print("Member: " +  obj);
             request.setAttribute("obj", obj);
            
             ActionForward forward = new ActionForward();
             forward.setRedirect(false);  // 
             forward.setPath("/obj.jsp");
             
             return forward;
     }
}
